import sys
from enum import Enum
from pathlib import Path


class SysType(Enum):
    WIN = 'Windows'
    MACOS = 'MacOS'
    LINUX = 'Linux'
    UNKNOWN = 'unknown'


def detect_system():
    """检测操作系统类型"""
    if sys.platform.startswith('win'):
        print("检测到Windows系统")
        return SysType.WIN
    elif sys.platform.startswith('darwin'):
        print("检测到macOS系统")
        return SysType.MACOS
    elif sys.platform.startswith('linux'):
        print("检测到Linux系统")
        return SysType.LINUX
    else:
        print("未知操作系统")
        return SysType.UNKNOWN


def get_ffmpeg_path():
    """获取ffmpeg可执行文件路径"""
    current_dir = Path(__file__).parent
    sys_type = detect_system()
    
    if sys_type == SysType.WIN:
        return {
            'ffmpeg': 'ffmpeg.exe',
            'ffprobe': 'ffprobe.exe',
            'ffplay': 'ffplay.exe'
            # 'ffmpeg': str(current_dir / 'ffmpeg.exe'),
            # 'ffprobe': str(current_dir / 'ffprobe.exe'),
            # 'ffplay': str(current_dir / 'ffplay.exe')
        }
    else:
        # # 首先尝试使用本地文件
        # local_ffmpeg = current_dir / 'ffmpeg'
        # if local_ffmpeg.exists():
        #     return {
        #         'ffmpeg': str(local_ffmpeg),
        #         'ffprobe': str(current_dir / 'ffprobe'),
        #         'ffplay': str(current_dir / 'ffplay')
        #     }
        # else:
        #     # 使用系统PATH中的ffmpeg
        #     return {
        #         'ffmpeg': 'ffmpeg',
        #         'ffprobe': 'ffprobe',
        #         'ffplay': 'ffplay'
        #     }

        return {
            'ffmpeg': 'ffmpeg',
            'ffprobe': 'ffprobe',
            'ffplay': 'ffplay'
        }


# 获取ffmpeg命令
ffmpeg_paths = get_ffmpeg_path()
ffmpeg_executable_cmd = ffmpeg_paths['ffmpeg']
ffprobe_executable_cmd = ffmpeg_paths['ffprobe']
ffplay_executable_cmd = ffmpeg_paths['ffplay']

app_version = 'v2.2'

# 系统类型
sys_type = detect_system()
